# 模拟两个进程，一个负责向队列写入数据，一个负责从队列读消息

from multiprocessing import Queue
from multiprocessing import Process
import time


def write(q: Queue):  # 往队列写入数据
    if not q.full():
        for i in range(5):
            message = "message " + str(i)
            q.put(message)
            print("写入 ", message)


def read(q: Queue):
    while not q.empty():
        message = q.get()
        print("读取内容： ", message)


if __name__ == "__main__":
    print("主进程启动------")

    queue = Queue()  # 创建一个队列，不限长度
    w = Process(target=write, args=(queue,))
    r = Process(target=read, args=(queue,))
    w.start()
    r.start()
    time.sleep(100)

    print("主进程结束------")
